<?php
class ModTypeAction extends BaseAction{
    public function index(){
       //查询新闻类型
        $newsInfo=M("newstypes")->select();
        $this->assign('newsInfo',$newsInfo);
        $this->display();
    }
    //删除新闻类型
    public function modtype($typeId){
        $sql1 = "delete from reviews where articleId in (select articleId from newsArticles where typeId={$typeId})";
        $sql2 = "delete from newsArticles where typeId={$typeId}";
        $sql3 = "delete from newsTypes where typeId={$typeId}";
        $result=M()->query($sql1);
        $result=M()->query($sql2);
        $result=M()->query($sql3);
        if($result>0){
            $this->success('删除新闻类型成功',__APP__."/Modtype/index.html");
        }else{
            $this->success('删除新闻类型失败',__APP__."/Modtype/index.html");
        }
    }
    //修改新闻类型
    public function update(){
        $typeId=$_GET['typeId'];
        $typeName = $_POST["typeName"];
        $articleNums = $_POST["articleNums"];
        $result=M('newstypes')->query("update newsTypes set typeName='{$typeName}',articleNums={$articleNums} where typeId={$typeId}");
        if($result>0){
            $this->success('更新新闻类型成功',__APP__."/Modtype/index.html");
        }else{
            $this->success('更新新闻类型失败',__APP__."/Modtype/index.html");
        }
    }
}